// pages/myWallet/myWallet.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 20,
    listData: [],
    summary: {
      amount: 0,
      settled_amount: 0,
      unsettled_amount: 0
    },
    isEnd: true
  },
  getData() {
    const that = this;
    let json = {
      token: app.globalData.token,
      start: 1,
      transfer: 0,
      page: that.data.page,
      limit: that.data.limit
    }
    let jsonData = app.utils.getSignData(json);
    wx.showLoading({
      title: '加载中...',
    })
    app.utils.post(app.api.reqUrls.proxylog, jsonData).then(res => {
      wx.hideLoading();
      if (res.status == 1) {
        that.setData({
          summary: res.result.summary,
          listData:res.result.list
        })
      } else {
        throw res.msg
      }
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    that.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const that = this;
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const that = this;
    if (!that.data.isEnd) {
      return
    }
    let json = {
      token: app.globalData.token,
      start: 0,
      transfer: 0,
      page: that.data.page + 1,
      limit: that.data.limit
    }
    let jsonData = app.utils.getSignData(json);
    wx.showLoading({
      title: '加载中...',
    })
    app.utils.post(app.api.reqUrls.proxylog, jsonData).then(res => {
      wx.hideLoading();
      if (res.status == 1) {
        wx.hideLoading();
        if (res.result.list.length == 0) {
          wx.showToast({
            title: '没有更多了',
            icon: 'none',
            duration: 1000
          })
          that.setData({
            isEnd: false
          })
        } else {
          that.setData({
            listData: [...that.listData, ...res.result.list],
            page: that.data.page + 1
          })
        }
      }
    })
  },
})